package ac.manchester.cs.afzal.term_classifier.nlp;

import java.io.*;
import java.util.*;
import ac.manchester.cs.afzal.term_classifier.miscellaneous.*;

import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * Company: The University of Manchester
 *
 * @author Hammad Afzal
 * @version 1.0
 *
 */
public class Parsed_Multi_Thread_Impl
{

    private String ANNOTATED_SENTENCES_CORPUS = "ANNOTATED_SENTENCES_CORPUS";
    private String PARSED_SENTENCES_PENN_CORPUS = "PARSED_SENTENCES_PENN_CORPUS";
    private String PARSED_SENTENCES_DEP_CORPUS = "PARSED_SENTENCES_DEP_CORPUS";
    private String STANFORD_PARSER_PATH = "STANFORD_PARSER_PATH";
    private String EN_SER_MODEL = "";

//    private int ELLIGIBLE_SENTENCE_LENGTH = 300;
    private LexicalizedParser lp;
    private Properties props;

    public Parsed_Multi_Thread_Impl()
    {
        try
        {
            props = new Properties();
            props.load(new FileInputStream("Term_Classification.properties"));

            PARSED_SENTENCES_PENN_CORPUS = props.getProperty(PARSED_SENTENCES_PENN_CORPUS);
            PARSED_SENTENCES_DEP_CORPUS = props.getProperty(PARSED_SENTENCES_DEP_CORPUS);
            ANNOTATED_SENTENCES_CORPUS = props.getProperty(ANNOTATED_SENTENCES_CORPUS);
            STANFORD_PARSER_PATH = props.getProperty(STANFORD_PARSER_PATH);

            EN_SER_MODEL = STANFORD_PARSER_PATH + "//englishPCFG.ser.gz";
        }
        catch (IOException ex)
        {
            Logger.getLogger(Parser_Single_Thread_Impl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void txt_to_penn_dep()
    {
        lp = new LexicalizedParser(EN_SER_MODEL);
        File txt_sentences_dir, input_file_doc, output_file_doc1, output_file_doc2;

        txt_sentences_dir = new File(ANNOTATED_SENTENCES_CORPUS);

        String[] txt_sentences_dir_array = txt_sentences_dir.list();

        for (String directory_name : txt_sentences_dir_array)
        {
            input_file_doc = new File(ANNOTATED_SENTENCES_CORPUS + "//" + directory_name);
            output_file_doc1 = new File(PARSED_SENTENCES_PENN_CORPUS + "//" + directory_name);
            output_file_doc1.mkdir();

            output_file_doc2 = new File(PARSED_SENTENCES_DEP_CORPUS + "//" + directory_name);
            output_file_doc2.mkdir();

            String[] list_files = input_file_doc.list();
            Parser_Threaded_Impl threaded_parser = new Parser_Threaded_Impl(list_files, ANNOTATED_SENTENCES_CORPUS, directory_name, PARSED_SENTENCES_PENN_CORPUS, PARSED_SENTENCES_DEP_CORPUS);
            Thread thread1 = new Thread(threaded_parser);
            thread1.start();
        }
    }

}
